﻿#include "users.h"
#include<drinks.h>
#include<hardware.h>
#include<iostream>
using namespace std;

users::users()
{

}
hardware colapush;
hardware spritepush;
hardware funadmin;

void users::shop() //购物
{
    drinks cola("可乐",price1,bottle1);
    drinks sprite("雪碧",price2,bottle2);
    cout<<"欢迎来到7号售卖机，请输入操作编号"<<endl;
    cout<<"1、cola、2、sprite、3、supply"<<endl;
    cin>>click;
    if(click=="1")
    {
        cola.information();
        supply();
        showmoney();

        cout<<"确认支付，点击4";
        cin>>clickpay;
        colapay();
    }
    if(click=="2")
    {
        sprite.information();
        supply();
        showmoney();
        cout<<"欲确认支付，点击4"<<endl;
        cin>>clickpay;
        spritepay();
    }
    if(click=="3")
    {
        funadmin.admin();
    }
}


void users::colapay()  // 可乐支付
{
    if(clickpay=="4")
    {
        if(money>price1&&bottle1!=0)
        {
            colapush.hardware1();
        }
        else
        {
            cout<<"余额不足或瓶数不足"<<endl;
        }
    }
}


void users::spritepay()  // 雪碧支付
{
    if(clickpay=="4")
    {
        if(money>price2&&bottle2!=0)
        {
            colapush.hardware1();
        }
        else
        {
            cout<<"余额不足或瓶数不足"<<endl;
        }
    }
}


void users::supply()
{
    if(click=="1"&&bottle1<5)
    {
        if(bottle1==0)
        {cout<<"已经没有可乐"<<endl;}
        else
        cout<<"可乐数量过低,尽快购买"<<endl;
    }
    if(click=="2"&&bottle2<5)
    {
        if(bottle2==0)
        {cout<<"已经没有雪碧"<<endl;}
        else
        cout<<"雪碧数量过低，尽快购买"<<endl;
    }
}


void users::showmoney()
{
    cout<<"当前余额为："<<money<<endl;
}
